/* ****************************************************************************
* Copyright (c) TCC - 2009 IME - USP. 
*
* This source code is subject to terms and conditions of the Microsoft Public License. 
* A copy of the license can be found in http://msdn.microsoft.com/en-us/library/dd228915.aspx. 
* By using this source code in any fashion, you are agreeing to be bound by the terms of the 
* Microsoft Public License.
*
* You must not remove this notice, or any other, from this software.
* ***************************************************************************/

namespace SoundLibrary
{

    enum OutputChannelsEnum
	{
		BOTH_CHANNELS = 0,
		LEFT_CHANNEL = 1,
		RIGHT_CHANNEL = 2,
		DOWNMIX_CHANNELS = 3
	}
	
	internal class OutputChannels
	{
        public static int BOTH_CHANNELS = 0;
		public static int LEFT_CHANNEL = 1;
		public static int RIGHT_CHANNEL = 2;
        public static int DOWNMIX_CHANNELS = 3;
		public static readonly OutputChannels LEFT = new OutputChannels(LEFT_CHANNEL);
		public static readonly OutputChannels RIGHT = new OutputChannels(RIGHT_CHANNEL);
		public static readonly OutputChannels BOTH = new OutputChannels(BOTH_CHANNELS);
		public static readonly OutputChannels DOWNMIX = new OutputChannels(DOWNMIX_CHANNELS);
		private int outputChannels;

        #region Properties

        virtual public int ChannelsOutputCode
        {
            get{return outputChannels;}

        }

        virtual public int ChannelCount
        {
            get{
                int count = (outputChannels == BOTH_CHANNELS) ? 2 : 1;
                return count;
            }

        }

        #endregion

        #region Public Methods

        static public OutputChannels fromInt(int code)
		{
			switch (code)
			{
				
				case (int)OutputChannelsEnum.LEFT_CHANNEL: 
					return LEFT;
				
				case (int)OutputChannelsEnum.RIGHT_CHANNEL: 
					return RIGHT;
				
				case (int)OutputChannelsEnum.BOTH_CHANNELS: 
					return BOTH;
				
				case (int)OutputChannelsEnum.DOWNMIX_CHANNELS: 
					return DOWNMIX;
				
				default: 
					throw new System.ArgumentException("Invalid channel code: " + code);
				
			}
		}
		
		public  override bool Equals(System.Object o)
		{
			bool equals = false;
			
			if (o is OutputChannels)
			{
				OutputChannels oc = (OutputChannels) o;
				equals = (oc.outputChannels == outputChannels);
			}
			
			return equals;
		}
		
		public override int GetHashCode()
		{
			return outputChannels;
        }

        #endregion

        #region Private Methods

        private OutputChannels(int channels)
        {
            outputChannels = channels;

            if (channels < 0 || channels > 3)
                throw new System.ArgumentException("channels");
        }

        #endregion

    }
}